<template>
    <a-card :bordered="false">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
            <h2 class="text-center  margin-bottom">任务执行列表</h2>
            <a-form layout="inline" @keyup.enter.native="searchQuery">
                <a-row :gutter="24">
                    <a-col :md="8" :sm="24">
                        <a-form-item label="任务创建时间">
                            <a-range-picker
                                :show-time="{ format: 'HH:mm' }"
                                :placeholder="['开始时间', '结束时间']"
                                v-model="rangeTime"
                                format="YYYY-MM-DD HH:mm"
                                @change="handleDateChange"
                            />
                        </a-form-item>
                    </a-col>
                    <a-col :span="6">
                        <a-form-item label="执行状态">
                            <a-select placeholder="执行状态" v-model="queryParam.executorState">
                                <a-select-option value="">全部</a-select-option>
                                <a-select-option value="0">待执行</a-select-option>
                                <a-select-option value="1">已完成</a-select-option>
                                <a-select-option value="2">已拒绝</a-select-option>
                            </a-select>
                        </a-form-item>
                    </a-col>
                    <a-col :span="6">
                        <a-form-item label="执行人姓名">
                            <a-input v-model="queryParam.executorName" placeholder="执行人姓名"/>
                        </a-form-item>
                    </a-col>
                    <a-col :span="6">
                        <a-form-item label="被执行单位">
                            <a-input v-model="queryParam.customerName" placeholder="被执行单位"/>
                        </a-form-item>
                    </a-col>
                    <a-col :span="6" >
                        <a-form-item label="任务类型">
                            <select-law-type :typesId="queryParam.typeId" @change="changeType" ></select-law-type>
                        </a-form-item>
                    </a-col>

                </a-row>

            </a-form>
        </div>
        <!-- 查询区域-END -->

        <!-- 操作按钮区域 -->
        <div class="table-operator" style="display: flex;justify-content: space-between;align-items: center;">
            <div>
                <a-button type="primary" @click="searchQuery" icon="search">查询数据列表</a-button>
                <a-button v-if="customerList.length <= 0" type="primary" @click="resetForm">重置查询</a-button>
            </div>
            <div>
                <a-button type="primary" icon="printer" v-print="'#printTableList'">打印</a-button>
            </div>
        </div>


        <!-- table区域-begin -->
        <div>
            <a-table
                ref="table"
                size="middle"
                bordered
                rowKey="id"
                :columns="columns"
                :dataSource="dataSource"
                :pagination="ipagination"
                :loading="loading"
                class="j-table-force-nowrap"
                @change="handleTableChange"
            >
                <template slot="htmlSlot" slot-scope="text">
                    <div v-html="text"></div>
                </template>
                <template slot="imgSlot" slot-scope="text">
                    <viewer>
                        <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
<!--                        <img v-else :src="`https://www.gzhc.vip/recycle/${text}`"  alt=""-->
<!--                             style="width: auto;height: 25px;"/>-->
                        <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
                    </viewer>
                </template>
                <template slot="imageSlot" slot-scope="text">
                    <viewer>
                    <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
<!--                    <img v-else v-for="(item,index) in text" :src="`https://www.gzhc.vip/recycle/${item}`" :key="index"  alt=""-->
<!--                         style="width: auto;height: 25px;margin-right: 5px"/>-->
                    <img v-else v-for="(item,index) in text" :src="getImgView(item)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;margin-right: 5px"/>
                    </viewer>
                </template>
                <template slot="fileSlot" slot-scope="text">
                    <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
                    <a-button
                        v-else
                        :ghost="true"
                        type="primary"
                        icon="download"
                        size="small"
                        @click="uploadFile(text)"
                    >下载
                    </a-button>
                </template>

            </a-table>
        </div>



        <div v-show="false">
            <div id="printTableList">
                <h2 style="text-align: center;font-weight: bold;">
                    任务执行列表
                </h2>
                <h3 v-if="rangeTime.length">时间 ： {{rangeTime[0]}} 至 {{rangeTime[1]}}</h3>
                <a-table
                    size="small"
                    bordered
                    rowKey="id"
                    :columns="columns"
                    :dataSource="dataSource"
                    :pagination="false"
                >
                    <template slot="htmlSlot" slot-scope="text">
                        <div style="color: black !important;" v-html="text"></div>
                    </template>
                    <template slot="imgSlot" slot-scope="text">
                        <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
                        <img v-else :src="getImgView(text)"  alt=""
                             style="width: auto;height: 25px;"/>
                    </template>
                    <template slot="imageSlot" slot-scope="text">
                        <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
                        <img v-else v-for="(item,index) in text" :src="getImgView(item)" :key="index"  alt=""
                             style="width: 30px;height: 25px;"/>
                    </template>

                </a-table>
            </div>
        </div>
    </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import SelectLawType from '@comp/Jane/SelectLawType'


export default {
    mixins: [JeecgListMixin, mixinDevice],
    components: {
        SelectLawType
    },
    data() {
        return {
            description: '任务执行列表',
            rangeTime: [],
            queryParam: {
                customerNumber: null,
                customerDepartmentId: null,
                creatTimeBegin: null,
                creatTimeEnd: null
            },
            // 表头
            columns: [],
            url: {
                list: '/hc/hcLawEnforcementPerform/webPage',
                exportXlsUrlOkForImages: '#'
            },
            dictOptions: {},
            customerList: [],
            editData: null,
            visible: false,
            deleteRemark: '',
            loading: false ,
        }
    },


    methods: {
        // 配置默认信息
        async initDictConfig(){
            for (let i in this.queryParam) {
                this.queryParam[i] = ''
            }
            let date = new Date()
            let time1 = new Date(date.setHours(0, 0, 0, 0)).Format('yyyy-MM-dd hh:mm')
            let time2 = new Date(date.setHours(0, 0, 0, 0) + (1000 * 60 * 60 * 24 - 1)).Format('yyyy-MM-dd hh:mm')
            this.queryParam.creatTimeBegin = time1;
            this.queryParam.creatTimeEnd = time2;
            this.rangeTime = [this.queryParam.creatTimeBegin, this.queryParam.creatTimeEnd];

            this.setColumns()
        },

        // 重置筛选表单
        resetForm : function(){
            this.initDictConfig();
            this.searchQuery();
        },

        handleDateChange(value, dateString) {
            this.rangeTime = dateString
            if (dateString[0]) {
                this.queryParam.creatTimeBegin = dateString[0]
            }
            if (dateString[1]) {
                this.queryParam.creatTimeEnd = dateString[1]
            }
        },

        searchQuery: function() {
            this.selectedRowKeys = []
            this.selectionRows = []
            this.loadData(1)
        },



        // 设置列
        setColumns() {
            let col = [
                {
                    title: '序号',
                    dataIndex: '',
                    key: 'rowIndex',
                    width: 60,
                    align: 'center',
                    customRender: function(t, r, index) {
                        return parseInt(index) + 1
                    }
                },
                {
                    title: '任务类型',
                    align: 'center',
                    dataIndex: 'taskName',
                },
                {
                    title: '任务标题',
                    align: 'center',
                    dataIndex: 'taskTitle',

                },
                {
                    title: '执法范围',
                    align: 'center',
                    dataIndex: 'scopeName'
                },
                {
                    title: '被执行机构名称',
                    align: 'center',
                    dataIndex: 'customerName'
                },
                {
                    title: '罚款金额',
                    align: 'center',
                    dataIndex: 'punishmentMoney'
                },
                {
                    title: '扣除分数',
                    align: 'center',
                    dataIndex: 'deductScore'
                },
                {
                    title: '执行人',
                    align: 'center',
                    dataIndex: 'executorName'
                },
                {
                    title: '同行人',
                    align: 'center',
                    dataIndex: 'membersNames'
                },
                {
                    title: '执行方式',
                    align: 'center',
                    dataIndex: 'executorMethod'
                },
                {
                    title: '执法条款',
                    align: 'center',
                    dataIndex: 'clauseName'
                },
                {
                    title: '执行开始时间',
                    align: 'center',
                    dataIndex: 'startExecutorTime'
                },
                {
                    title: '执行结束时间',
                    align: 'center',
                    dataIndex: 'endExecutorTime'
                },
                {
                    title: '执行状态',
                    align: 'center',
                    dataIndex: 'executorState',
                    customRender:function (text) {
                        if(text === 0){
                            return "待执行";
                        }else if(text === 1){
                            return "已完成";
                        }else if(text === 2){
                            return "已拒绝";
                        }else{
                            return text;
                        }
                    }
                },
                {
                    title: '执法图片',
                    align: 'center',
                    dataIndex: 'images',
                    scopedSlots: {customRender: 'imageSlot'}
                },
                {
                    title: '机构地址',
                    align: 'center',
                    dataIndex: 'address'
                },
                {
                    title: '被执行单位签字',
                    align: 'center',
                    dataIndex: 'customerUrl',
                    scopedSlots: {customRender: 'imgSlot'}
                },
                {
                    title: '执行人签字',
                    align: 'center',
                    dataIndex: 'executorUrl',
                    scopedSlots: {customRender: 'imgSlot'}
                },
                {
                    title: '执法结果内容',
                    align: 'center',
                    dataIndex: 'resultsContext'
                },
                {
                    title: '备注',
                    align: 'center',
                    dataIndex: 'specialRemake'
                },
            ]
            this.columns = col
        },
        // 选择任务类型
        changeType(value) {
            this.queryParam.typeId = value;
            this.loadData(1)
        },

    }
}


</script>
<style scoped>
@import '~@assets/less/common.less';
</style>